import { ref } from "vue";
import { defineStore } from "pinia";

export const useTabStore = defineStore(
  "tabs-routes",
  () => {
    const tabs = ref([
      {
        path: "/dashboard",
        title: "仪表盘",
      },
    ]);
    const addTab = (val) => {
      if (findByTab(val.path)) return;
      tabs.value.push(val);
    };
    const removeTab = (path) => {
      tabs.value = tabs.value.filter((item) => item.path !== path);
    };
    const findByTab = (path) => tabs.value.find((item) => item.path === path);
    return {
      tabs,
      addTab,
      removeTab,
    };
  },
  {
    persist: true,
  }
);
